package PTA_6_49;


import java.util.Scanner;

/* 请在这里填写答案 */
interface Goods{
    public String getName();
    public double getPrice();
}

class ShopCar {
    Goods[] goods;
    int foot = 0;
    public ShopCar(int n) {
        goods = new Goods[n];
    }
    public void add(Goods goods) {
       if(this.foot<this.goods.length) {
           this.goods[foot] = goods;
           foot++;
           System.out.println("添加成功！");
       }
       else {
           System.out.println("添加失败！");
           return ;
       }
    }
    public void remove(int n) {
        if(n < this.goods.length && n >= 0) {
            for (int i = n; i < goods.length - 1 ; i++) {
                goods[i] = goods[i+1];
            }
            this.goods[goods.length-1] = null;

        }
    }
    public double check() {
        double sum = 0.0;
        for (int i = 0; i < goods.length; i++) {
            if(goods[i] != null) {
                sum+=goods[i].getPrice();
            }
        }
        return sum;
    }

    public Goods[] getGoods() {
        return this.goods;
    }
}
class Book implements Goods {
    String name;
    double price;

    public Book( String name, double price) {
        this.name = name;
        this.price = price;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public double getPrice() {
        return price;
    }
}

class Drink implements Goods {
    String name;
    double price;

    public Drink(String name, double price) {
        this.name = name;
        this.price = price;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public double getPrice() {
        return price;
    }

}


public class Test_1 {
    public static void main(String[] args) {
        int n;
        Scanner scan=new Scanner(System.in);
        n=scan.nextInt();
        ShopCar sc=new ShopCar(n);
        sc.add(new Book("Java程序设计",78.5));
        sc.add(new Book("图像处理",44.5));
        sc.add(new Book("高等数学",34.8));
        sc.add(new Drink("绿茶",2.5));
        sc.add(new Drink("雪碧",3.5));
        sc.add(new Drink("可乐",5.5));
        sc.remove(3);
        for(int i=0;i<sc.getGoods().length;i++){
            if(sc.getGoods()[i]!=null)
                System.out.println("商品名称："+sc.getGoods()[i].getName()+"，价格："+sc.getGoods()[i].getPrice());
        }
        System.out.println("结账："+sc.check());
    }

}